import { prop, modelOptions,Ref} from '@typegoose/typegoose';
import { ApiProperty } from '@nestjs/swagger';
import { hashSync } from 'bcryptjs'
import { Course } from '@libs/db/models/course.model' 


  // 给添加的数据加入时间戳
  @modelOptions({
    schemaOptions:{
        timestamps:true
    }
})
    
  export class User{
  
    @ApiProperty({description:'用户名',example:'user1'})
    @prop()
    username: string
  
    @ApiProperty({description:'密码',example:'password1'})
    @prop({
      get(val){
        return val
      },
      //返回一个新值
      set(val){
        return val ? hashSync(val) : val
      }
    })
    password: string
    
    @prop({ ref:'Course' })
    liked:Ref<Course>[]
  }